package com.iqiyi.pps.epg.api.server.impl;

import com.iqiyi.pps.epg.api.server.iservice.StreamApiService;
import com.iqiyi.pps.epg.api.server.proxy.StreamProxy;
import com.iqiyi.pps.epg.api.utils.CrossDataLocalPool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by karkarrotxu on 2017/4/14.
 */
@Service("streamApiServiceImpl")
public class StreamApiServiceImpl extends ApiServiceImpl implements StreamApiService {
    @Autowired
    private StreamProxy streamProxy;

    // 频道流管理
    public String createStream(String fatherId, String streamName, String streamIp, String streamType, String peerCount,
                               String bcsNum, String cutterIdFlv, String cutterIdTs, String dest, int streamApiVersion,
                               String dolbyStreamName, String dolbyStreamUrl, String dolbyAudioChannel, int encodeType, String streamAddress, int playType, int backupEachOther) {
        CrossDataLocalPool.set(getCrossData());
        return streamProxy.createStream(fatherId, streamName, streamIp, streamType, peerCount,
                bcsNum, cutterIdFlv, cutterIdTs, dest, streamApiVersion,
                dolbyStreamName, dolbyStreamUrl, dolbyAudioChannel, encodeType, streamAddress,playType,backupEachOther);
    }

    public String deleteStreamById(Long id) {
        CrossDataLocalPool.set(getCrossData());
        return streamProxy.deleteStreamById(id);
    }

    public String getStreamList(String fatherId) {
        CrossDataLocalPool.set(getCrossData());
        return streamProxy.getStreamList(fatherId);
    }

    public String getStreamById(Long id) {
        CrossDataLocalPool.set(getCrossData());
        return streamProxy.getStreamById(id);
    }

    public String editStream(String id, String fatherId, String streamIp, String streamType, String peerCount, String bcsNum,
                             String cutterIdFlv, String cutterIdTs, String isEnable, String dest, int streamApiVersion, int playType, int backupEachOther) {
        CrossDataLocalPool.set(getCrossData());
        return streamProxy.editStream(id, fatherId, streamIp, streamType, peerCount, bcsNum,
                cutterIdFlv, cutterIdTs, isEnable, dest, streamApiVersion, playType, backupEachOther);
    }

    // 收集编码器的信号源信息
    public String encodeServerStat(String serverIp, String signalDesc, String inputSignal, String outputSignal,
                                   String extraData, int encodeType, int status) {
        CrossDataLocalPool.set(getCrossData());
        return streamProxy.encodeServerStat(serverIp, signalDesc, inputSignal, outputSignal,  extraData,  encodeType,
        status);
    }

    // 获取cutterId 使用情况
    public String getCutterIdInfo(int maxVal, String cutterType, String sortType) {
        CrossDataLocalPool.set(getCrossData());
        return streamProxy.getCutterIdInfo(maxVal, cutterType, sortType);
    }

    @Override
    public String getStreamSearchList(String fatherId, String streamName, Integer pageNo, Integer pageSize) {
        CrossDataLocalPool.set(getCrossData());
        return streamProxy.getStreamSearchList(fatherId,  streamName,  pageNo,  pageSize);
    }

    @Override
    public String switchBackup(String fatherId, String qipuId) {
        CrossDataLocalPool.set(getCrossData());
        return streamProxy.switchBackup(fatherId, qipuId);
    }
}
